﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Abp.Dependency;
using Abp.Domain.Repositories;
using Abp.Domain.Uow;
using Abp.RemoteEventBus;
using Abp.Runtime.Caching;
using FwProject.Core.Distribution;
using FwProject.Core.Restaurant;
using FwProject.Distribution;
using FwProject.Distribution.Dto;
using FwProject.Restaurant;
using FwProject.Users;
using Microsoft.EntityFrameworkCore;
using Castle.Core.Logging;
using Newtonsoft.Json;
using FwProject.Comm.Sms;
using FwProject.Comm;

namespace FwProject.RemoteEventBus
{

   
        [RemoteEventHandler(ForType = RemoteTypeHelp.TypeSmsObject, ForTopic = RemoteTypeHelp.TopicSms)]
        public class SmsMessage : IRemoteEventHandler, ITransientDependency
        {
            public ILogger logging { get; set; }
            public SmsMessage()
            {
              
                logging = NullLogger.Instance;
            

            }
            [UnitOfWork]
            public void HandleEvent(RemoteEventArgs eventArgs)
            {
                try
                {
                    var model=   JsonConvert.DeserializeObject<SmsObject>(eventArgs.EventData.Data[RemoteTypeHelp.SmsObject].ToString());
                    SmsUntil smsUntil = new SmsUntil();
                    Task.Run(() => smsUntil.Send(model));
                }
                catch (Exception exe)
                {
                    logging.Error($"{nameof(SmsMessage)}{exe.ToString()}",exe);

                }
                finally
                {
                    logging.Info($"{nameof(SmsMessage)}");
                }


            }
        }
    
}
